package org.vaadinetherealintegration.client.example4;

import org.vaadinetherealintegration.client.ExampleInterface;

import etrl.core.Geode;
import etrl.core.Group;
import etrl.core.LightStore;
import etrl.core.Lights;
import etrl.core.Node;
import etrl.core.Transform;
import etrl.core.Viewer;
import etrl.resources.Resources;
import etrl.vecmath.Quat4f;
import etrl.vecmath.Vector3f;

public class Example4 implements ExampleInterface
{
	String stone_wall = "VAADIN/widgetsets/org.vaadinetherealintegration.MyWidgetSet/stone_wall.bmp";
    String hud = "VAADIN/widgetsets/org.vaadinetherealintegration.MyWidgetSet/hud.png";
    
	/**
	 * Viewer
	 */
	private Viewer _viewer;
		
	/**
	 * Constructor
	 * @param[in] viewer
	 */
	public Example4(Viewer viewer)
	{
		_viewer = viewer;
	}
	
	
	public Node buildSceneRoot()
	{
		Group root = new Group();
		
		Transform cubeTransform = new Transform();
		cubeTransform.setPosition(new Vector3f(0.f, 0.f, -10.f));
		cubeTransform.setUniformScale(5.f);
		cubeTransform.setNodeCallback(new RotationCallback(cubeTransform));
		cubeTransform.addTexture(stone_wall, 1.f, 1.f);
	
		Geode cubeGeode = new Geode();
		cubeGeode.addDrawable(new Cube());
		cubeTransform.addChild(cubeGeode);
		
		LightStore.getInstance().createLight("light0");
		LightStore.getInstance().setLightPositionDirection("light0", new Vector3f(0.f, 20.f, 0.f));
		
		Lights lights = new Lights();
		lights.addLight("light0");
		
		lights.addChild(cubeTransform);
		
		Hud hud = new Hud(_viewer);
		root.addChild(hud.getCamera());
		root.addChild(lights);
		
		return root;
	}

	
	public Vector3f getInitialCameraPos()
	{
		return new Vector3f(0.f, 0.f, 0.f);
	}

	
	public Quat4f getInitialCameraOrientation()
	{
		return new Quat4f(0.f, 0.f, 0.f, 1.f);
	}

	
	public void atExit()
	{
		// clear example resources
		_viewer.unloadResources();
	}

	
	public void atStart()
	{
		// Load example texture resources
		Resources.instance().addTextureToLoad(stone_wall, true);
		Resources.instance().addTextureToLoad(hud, true);
		_viewer.loadResources();
	}

}
